<template>
  <div class="mask" v-show="showDialog">
    <div class="dialog">
      <div class="dialog-header">
        <div class="title pos-left">{{take}} - {{dialogTitle}}-所选时间区间内接警{{jjTime}}次</div>
        <ul class="tools pos-right">
          <li class="item">
            <button class="btn" type="button" @click="closeDialog">
              <i class="icon icon-close"></i>
            </button>
          </li>
        </ul>
      </div>
      <div class="dialog-body scroll">
        <ul class="panel">
          <li class="item">
            <input 
            type="date" 
            value 
            class="datepicker" 
            v-model="startTime"
            :max="timeLimit" 
            :min="timeMin"
            placeholder="开始时间">
          </li>
          <li class="item">至</li>
          <li class="item">
            <input 
            type="date" 
            value 
            class="datepicker" 
            v-model="endTime" 
            :max="timeLimit"
            :min="timeMin"
            placeholder="结束时间">
          </li>
          <li class="item">
            <input 
            type="text"
            class="textbox" 
            v-model="keyword" placeholder="请以装备类型作为关键字搜索">
          </li>
          <li class="item">
            <button class="btn bg-blue" type="button" @click="query()">
              <span class="text">查询</span>
            </button>
          </li>
        </ul>
        <table class="dtable">
          <thead>
            <tr>
              <td>序号</td>
              <td>设备名称</td>
              <td>投用年份</td>
              <td>装备类型</td>
              <td>装备产地</td>
              <td>库存</td>
              <td>报损</td>
              <td>报修</td>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item,idx) in list" :key="idx">
              <td style="width:5%;">{{idx + 1}}</td>
              <td style="width:20%;">
                <div :title="item.eqName">{{item.eqName}}</div>
              </td>
              <td style="width:20%;">
                <div :title="item.eqTourTime">{{item.eqTourTime || '暂无信息'}}</div>
              </td>
              <td style="width:20%;">
                <div :title="item.eqClassify">{{item.eqClassify || '暂无信息'}}</div>
              </td>
              <td style="width:15%;">
                <div :title="item.eqChanDi">{{item.eqChanDi || '暂无信息'}}</div>
              </td>
              <td style="width:10%;">
                <div :title="item.eqStock">{{item.eqStock || '0'}}</div>
              </td>
              <td style="width:5%;">
                <div :title="item.eqDamage">{{item.eqDamage || '0'}}</div>
              </td>
              <td style="width:5%;">
                <div :title="item.eqSend">{{item.eqSend || '0'}}</div>
              </td>
            </tr>
          </tbody>
        </table>
        <x-loading :show="showLoading"></x-loading>
        <x-pager
          :page="page"
          :page-size="pageSize"
          :total="total"
          :max-page="maxPage"
          @pagehandler="pageHandler"
        ></x-pager>
      </div>
    </div>
  </div>
</template>
<script>
import Pager from "@/components/Pager";
import Loading from "@/components/Loading";
import axios from "axios";

export default {
  data() {
    return {
      keyword: "",
      list: [],
      listHasData: false,
      page: 0,
      pageSize: 10,
      total: 10,
      maxPage: 10,
      jjTime:0,
      showDialog: false,
      showLoading: false,
      dialogTitle: "装备清单",
      equipmentType: null,
      startTime:this.dateShift(-365),
      endTime:this.today(),
      timeLimit:this.today(),
      timeMin:this.dateShift(-365),
    };
  },
  components: {
    "x-pager": Pager,
    "x-loading": Loading
  },
  props: {
    take: String,
    show: Boolean
  },
  methods: {
    
    pageHandler(page) {
      this.page = page;
      let params = {
        startTime: this.startTime + ' 00:00:00',
        endTime: this.endTime + ' 23:59:59',
        eqName: this.equipmentType,
        keyword: this.keyword,
        pageSize: this.pageSize,
        pageindex: this.page,
        HTTEST: "test"
      };
      let $this = this;
      this.showLoading = true;
      axios
        .get(this.URLHEAD + "YZT_XFZBJCJ_Details", {
          params: params
        })
        .then(res => {
          let data = res.data;
          this.list = data.Data.list;
          this.jjTime=data.Data.count;
          this.total = data.count;
          this.showLoading = false;
        });
    },
    query(val) {
      this.equipmentType = val?val:this.equipmentType;
        if(val==undefined){
        this.startTime=this.startTime;
        this.endTime=this.endTime
      }
      else{
         this.startTime=this.$parent.startTime;
         this.endTime=this.$parent.endTime;
      }
      this.showDialog = true;
      this.list = [];
      this.pageHandler(1);
    },
    reset() {
      this.keyword = "";
      this.disasterType = "";
      this.page = 0;
      this.pageSize = 10;
      this.total = 10;
    },
    closeDialog() {
      this.showDialog = false;
      this.reset()
    }
  },
  created() {
    //this.getOrgData();
  }
};
</script>